package cn.rxls.admin.shop.controller;

import cn.rxls.admin.shop.dto.LoginDTO;
import cn.rxls.admin.shop.dto.PageUserDTO;
import cn.rxls.admin.shop.entity.Result;
import cn.rxls.admin.shop.entity.User;
import cn.rxls.admin.shop.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 用户表(User)表控制层
 */
@RestController
@RequestMapping("user")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    /**
     * 登录
     *
     * @param dto 参数对象
     * @return 所有数据
     */
    @PostMapping("/login")
    public Result<User> selectAll(@RequestBody LoginDTO dto) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getAuto, dto.getAuto()).eq(User::getPassword, dto.getPassword());
        User one = userService.getOne(wrapper);
        if (Objects.isNull(one)) {
            return Result.error("登录失败");
        }
        return Result.success("登录成功",one);
    }

}

